/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-12 09:54:27
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-16 07:04:59
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/custom_tile.dart';
import 'package:flutter_data_center/controller/home_controller.dart';
import 'package:flutter_data_center/screens/module/module_screens.dart';
import 'package:flutter_data_center/utills/navigator_utils.dart';
import 'package:get/get.dart';
import 'menu_item.dart';

class MenuList extends StatelessWidget {
  const MenuList({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return GetBuilder<HomeController>(
        builder: (_controller) => Column(
              mainAxisSize: MainAxisSize.max,
              children: [
                CustomTile(
                    title: "智慧应用",
                    tap: () {
                      NavigatorUtils.pushPageByFade(
                        context: context,
                        targetPage: ModuleScreen(),
                        isReplace: false,
                        startMills: 500,
                      );
                      // Get.toNamed("/module");
                    }),
                SizedBox(height: 20),
                Container(
                  constraints:
                      BoxConstraints.expand(height: (size.width - 32) / 3 * 2),
                  width: double.infinity,
                  child: _controller.moduleList.length > 0
                      ? GridView.builder(
                          physics: NeverScrollableScrollPhysics(),
                          padding: EdgeInsets.all(5),
                          gridDelegate:
                              SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 3,
                            crossAxisSpacing: 20,
                            mainAxisSpacing: 15,
                            childAspectRatio: 1.1,
                          ),
                          itemCount: 6,
                          itemBuilder: (context, index) =>
                              MenuItem(module: _controller.moduleList[index]),
                        )
                      : Center(
                          child: SizedBox(
                            height: 80,
                            width: 80,
                            child: CircularProgressIndicator(),
                          ),
                        ),
                ),
              ],
            ));
  }
}
